﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using GoTextPalm.Core.Localization;
using System.Windows.Forms;
using System.IO;

namespace GoTextPalm
{
    public static class Utility
    {
        public static void FireGenericException(Exception e)
        {
            String str = "Program aborted with the following exception: {0}\n\rA file called debug.txt has been created in the application folder";
            String dbgFile = Program.Path + @"\debug.txt";
            FileStream fs = File.Create(dbgFile);
            StreamWriter sw = new StreamWriter(fs);
            sw.WriteLine("Message: " + e.Message);
            sw.WriteLine("StackTrace: " + e.StackTrace);
            sw.Flush();
            sw.Close();
            fs.Close();
            MessageBox.Show(string.Format(str, e.Message), "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
        }

        public static String Tr(String tr, String defValue)
        {
            try
            {
                return ResourceManager.Instance.GetString(tr);
            }
            catch
            {
                return defValue;
            }
        }
    }
}
